local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.Client_PlayerComponent());

local CallBackManager = ClientOHOH.load.CallBackManager();
local BattleWaveInfoGui= _G.ClientOHOH.load.UIManager():CreateUI("BattleWaveInfoGui",require(script.BattleWaveInfoGui))

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);	
    self.ConList={}
	self.parent.BattleSateEvent:Connect(function(isBattle,ballte)
		if isBattle then
            self:Show(ballte)
		else
            self:Hide()
		end
	end)

    
    CallBackManager:AddRbxConnect(self,BattleWaveInfoGui.insts.ExitBtn.Activated, function()

        self.parent:StopAutoAttackState()
        self.parent:GetComponent(_G.CommonOHOH.load.Common_AttackCtrl()):ExitBattle()

    end);
    
end

function M.dtor(self)

    self:RemoveAllCon()
	M.super.dtor(self);
end;
function M.RemoveAllCon(self)
    for _,con in pairs(self.ConList) do
        con:Disconnect()
    end
    self.ConList={}
end


function M.Show(self,ballte)

    self.Battle=ballte

    self.Battle:AttributeValueChanged("WaveIndex",function()
        self:UpdateWaveProgress()
    end)
    self.Battle:AttributeValueChanged("killed",function()
       self:UpdateKilled()
    end)

    self:UpdateWaveProgress()
    self:UpdateKilled()

    BattleWaveInfoGui:Show()


end

function M.Hide(self)
    BattleWaveInfoGui:Hide()
    self:RemoveAllCon()
end

function M.UpdateWaveProgress(self)

    BattleWaveInfoGui:UpdateWaveProgress( self.Battle.attribute.WaveIndex+1,self.Battle.attribute.WaveCount)
    local ctrl=self.Battle:GetPrivateComponent("AttCtrl")
    self.parent.character:SetCFrame(ctrl:FindPlayerCFrame())
end

function M.UpdateKilled(self)
    BattleWaveInfoGui:UpdateOneWave(self.Battle.attribute.killed,self.Battle.attribute.MonsterCount)
end




return M